Well, there are ways to do this, but malloc() is the best in terms of having easiness, neatness. For your compiler which doesn't use the C99 standard I suppose.
If you cannot use malloc() then the next best thing is to declare a maximum size of the
array. Then you can just use temp[maximum_size].
If you are uncertain of the size or it is too big then you should pass a duplicate of the array inside the function. Like void reverse(int a[], int temp[], int size). You would have the duplicate array in main of course.
MORE importantly you have to think this. How are the values of a passed to the program. If you have a[] = {2,1,3,4; then you now that you have 4 elements in a. So you you declare int temp[4]. The point of passing size in the reverse function is pointless! It has no use, you know the size. It is 4.
Now. If the values where passed from a user then you would have to declare a with the size of the input entered in the first place before worrying about anything else! This can only be done with malloc() or by declaring again the array with a maximum size.
In any case, whatever you do with a you can do with temp. If you declare a as a 4-element array you already did, you should do that for temp
EDIT:
you would do:
Code:
int* temp;
temp = malloc(size*sizeof(int));
Thus allocating space. Not that since temp is a pointer you can use []. Then you use it as you did. Before the end of the function you would have to do:
To free the memory (not that it won't work if you don't)
Google malloc()/free and search for more details